# -*- coding: utf-8 -*-

class Node():
    def __init__(self, NodeValue, EdgeValue):
        self.EdgeValue = EdgeValue;
        self.NodeValue = NodeValue
        self.Next = None

class AdjacencyTable():
    def __init__(self, Lines):
        self.Lines = Lines
    def getTopNode(self):
        for k in self.Lines:
            print("图节点：", k)
    def addNewEdgeNode(self, TopKey, NodeValue, EdgeValue):
        if TopKey in self.Lines:
            Address = self.Lines[TopKey]
            if Address is None:
                self.Lines[TopKey] = Node(NodeValue, EdgeValue)
            else:
                while Address:
                    if Address.Next:
                        Address = Address.Next
                    else:
                        Address.Next = Node(NodeValue, EdgeValue)
                        break
        else:
            print('无该图节点：', TopKey)
            
    def printAll(self):
        if self.Lines is None:
            print('图没有节点！')
        else:
            for k, v in self.Lines.items():
                print('图节点：', k)
                while v:
                    print('其连接节点是%d，连接边是%d' % (v.NodeValue, v.EdgeValue))
                    v = v.Next
            
TopNode = {1:None, 2:None, 3:None, 4:None, 5:None, 6:None, 7:None}        
CityLine = AdjacencyTable(TopNode)
CityLine.addNewEdgeNode(1,2,1)
CityLine.addNewEdgeNode(1,3,2)
CityLine.addNewEdgeNode(1,4,3)
CityLine.addNewEdgeNode(2,6,4)
CityLine.addNewEdgeNode(3,6,5)
CityLine.addNewEdgeNode(3,5,6)
CityLine.addNewEdgeNode(4,5,7)
CityLine.addNewEdgeNode(5,7,8)
CityLine.addNewEdgeNode(6,7,9)
CityLine.getTopNode()

print('图遍历：')
CityLine.printAll()

